import React from 'react';

const Checkbox = React.createClass({
  getInitialState() {
    return {
      checked: this.props.checked
    };
  },
  // componentWillReceiveProps(nextProps) {
  //   this.handleChange(null, nextProps.checked);
  // },
  handleChange(e, checked) {
    const data = {};
    data.target = e.target || e.srcElement;
    data.value = data.target.checked;
    data.name = this.props['data-target'];
    data.checked = e.target.checked;
    if (this.props.onChange) {
      this.props.onChange(data);
    }
  },
  render() {
    const props = this.props;
    return (
      <label className={'checkbox' + (props.className ? ' ' + props.className : '')}>
        <input
          type="checkbox"
          className="checkbox-input"
          data-target={props['data-target']}
          id={props.id}
          disabled={props.disabled}
          checked={props.checked}
          value={props.checked}
          onChange={this.handleChange}
        />
        <span className={props.labeStyle}>{props.label}</span>
      </label>
    );
  }
});
export default Checkbox;
